/*
 * action 类型
 */

export const INCREASE = 'increase';
export const DESCREASE = 'descrease';
export const INCREASE_IF_ODD = 'increase_if_odd';
export const INCREASE_DELAY = 'increase_delay';

/*
 * 其它的常量
 */

/*
 * action 创建函数
 */

export function increaseAction() {
    return { type: INCREASE };
}

export function decreaseAction() {
    return { type: DESCREASE };
}

export function increaseIfOddAction() {
    return ((dispatch, getState) => {
        if(getState().value % 2 === 0) {
            return;
        }
        dispatch(increaseAction());
    });
}

export function increaseDelayAction(delay = 1000) {
    return ((dispatch, getState) => {
        setTimeout(() => {
            dispatch(increaseAction());
        }, delay);
    });
}